
from django import template
from web import models
from django.urls import reverse

register = template.Library()

@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    # 1 当前用户创建的项目
    my_project_list = models.Project.objects.filter(
        creator=request.tracer_obj.user_obj
    )
    # 2 参与的项目
    join_project_list = models.ProjectUser.objects.filter(
        user=request.tracer_obj.user_obj
    )

    return {'my':my_project_list ,'join':join_project_list, 'request': request}

@register.inclusion_tag('inclusion/manage_menu_list.html')
def manage_menu_list(request):

    data_list = [
        {'title':'概览', 'url': reverse('dashboard',kwargs={'pro_id': request.tracer_obj.project.id })},
        {'title':'问题', 'url': reverse('issues',kwargs={'pro_id': request.tracer_obj.project.id })},
        {'title':'统计', 'url': reverse('statistics',kwargs={'pro_id': request.tracer_obj.project.id })},
        {'title':'wiki', 'url': reverse('wiki',kwargs={'pro_id': request.tracer_obj.project.id })},
        {'title':'文件', 'url': reverse('file',kwargs={'pro_id': request.tracer_obj.project.id })},
        {'title':'配置', 'url': reverse('setting',kwargs={'pro_id': request.tracer_obj.project.id })},
    ]

    for i in data_list:
        # 当前访问路径如果和某个功能路径相同，那么将功能路径对应的字典数据里面加上一个class='active'，那么在manage_menu_list.html文件中渲染时，就可以给对应功能的li标签加上active属性，就有选中效果了。
        if request.path == i.get('url'):
            i['class'] = 'cc'

    return {'data_list': data_list}














